Getting Started with the PI Camers

  • Install the camera
  • Enable the camera
  • Take a picture with Python
  • Use cheese to take a picture

Official Documentation

https://picamera.readthedocs.io/en/release-1.12/

Enable Raspberry PI Camera

User the raspi-config either command line or graphical and select enable the camera.

Use some Python to use the Camera

This is a built in library and should be on the Raspberry PI by default.


In [4]:
from time import sleep
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1024, 768)
camera.start_preview()
# Camera warm-up time
sleep(2)
camera.capture('foo.jpg')
camera.close()

In [3]:
from picamera import PiCamera
from time import sleep

camera = PiCamera()

camera.start_preview()
sleep(10)
camera.stop_preview()
sleep(10)
camera.start_preview()
sleep(10)
camera.close()

In [2]:

Trouble shooting and notes

The PI Camera doesn't present itself to the system even though it's working through Python. What's not configured are the basic device nodes that Linux would like to use. So a program like "cheese" will not find the camera.

sudo apt-get install cheese

This would install cheese but this error would occur: No device found

ls /dev/vid*

Would return no device.

The Fix

The low linux kernel isn't loaded. So we have to do it manually.

sudo modprobe bcm2835-v4l2

Use the Pi Camera with openCV

Connect the PiCamera to openCV https://picamera.readthedocs.io/en/release-1.12/recipes2.html


In [ ]:


In [5]:
from time import sleep
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1024, 768)
camera.start_preview()
# Camera warm-up time
sleep(2)
camera.capture('foo.jpg', resize=(320, 240))
camera.close()

In [ ]: